<template>
	<custom-form-layout>
		<fui-form>
			<custom-form-item-card>
				<fui-form-item label="驳回原因" asterisk>
					<template #vertical>
						<fui-radio-group v-model="formData.rejectReason">
							<fui-label v-for="item in rejectReasonList" :key="item.value">
								<fui-list-cell>
									<view class="fui-align__center">
										<fui-radio :value="item.value"></fui-radio>
										<fui-text class="m-l-16" :text="item.label"></fui-text>
									</view>
								</fui-list-cell>
							</fui-label>
						</fui-radio-group>
					</template>
				</fui-form-item>
				<fui-form-item label="说明" :bottom-border="false">
					<template #vertical>
						<fui-textarea :border-top="false" placeholder="说明原因"></fui-textarea>
					</template>
				</fui-form-item>
			</custom-form-item-card>
		</fui-form>
		<template #footer>
			<fui-row :gutter="16">
				<fui-col :span="12">
					<fui-button background="#F2F3FF" color="#0052D9" @click="onCancel">取消</fui-button>
				</fui-col>
				<fui-col :span="12">
					<fui-button @click="submit">确认</fui-button>
				</fui-col>
			</fui-row>
		</template>
	</custom-form-layout>
</template>

<script>
	import {
		defineComponent
	} from "vue"
	import {
		mapState
	} from 'pinia'
	import {
		useSyStemStore
	} from "../../store/modules/system"
	import {
		getDicValue
	} from "../../utils/util"
	import {
		DIC_KEY
	} from "../../config/dicKey-config"
	import form from '@/components/firstui/fui-validator/fui-validator'
	import {
		WorkOrderReviewApi
	} from "../../api/workOrder"
	import {
		SubPages
	} from "../../config/router-config"
	import _ from 'lodash'
	export default defineComponent({
		data() {
			return {
				formData: {
					// 工单号
					orderNum: '',
					// 驳回原因
					rejectReason: '',
					// 驳回说明
					rejectDescribe: '',
				}
			}
		},
		computed: {
			...mapState(useSyStemStore, ['dicList']),
			rejectReasonList() {
				return getDicValue(this.dicList, DIC_KEY.obs_no_examine)

			}
		},
		onLoad(options) {
			this.formData.orderNum = options.orderNum
		},
		methods: {
			submit: _.debounce(async function(orderNum, cb) {
				const rules = [{
					name: "rejectReason",
					rule: ["required"],
					msg: ["请选择驳回原因"]
				}];
				try {
					let {
						isPassed,
						errorMsg
					} = form.validator(this.formData, rules)
					if (isPassed) {
						await WorkOrderReviewApi.reject(this.formData)
						this.fui.toast('操作成功!')
						_.delay(() => {
							uni.redirectTo({
								url: SubPages.WORK_ORDER_REVIEW_INDEX.router
							})
						}, 1000)
					} else {
						this.fui.toast(errorMsg)
					}
				} catch (err) {
					console.error(err);
					uni.showToast({
						title: err,
						icon: 'error'
					})

				}
			}, 300),
			onCancel() {
				uni.navigateBack()
			},
		}
	})
</script>

<style>

</style>